using UnityEngine;

[AddComponentMenu("Camera-Control/Mouse Look")]
public class MouseLookiPhone : MonoBehaviour
{
	public enum RotationAxes
	{
		MouseXAndY,
		MouseX,
		MouseY
	}

	public RotationAxes axes;

	public float sensitivityX = 15f;

	public float sensitivityY = 15f;

	public float minimumX = -360f;

	public float maximumX = 360f;

	public float minimumY = -60f;

	public float maximumY = 60f;

	private float rotationX;

	private float rotationY;

	private float inputX;

	private float inputY;

	private Quaternion originalRotation;

	private void Update()
	{
		if (axes == RotationAxes.MouseXAndY)
		{
			rotationX += inputX * sensitivityX;
			rotationY += inputY * sensitivityY;
			rotationX = ClampAngle(rotationX, minimumX, maximumX);
			rotationY = ClampAngle(rotationY, minimumY, maximumY);
			Quaternion rhs = Quaternion.AngleAxis(rotationX, Vector3.up);
			Quaternion rhs2 = Quaternion.AngleAxis(rotationY, Vector3.left);
			base.transform.localRotation = originalRotation * rhs * rhs2;
		}
		else if (axes == RotationAxes.MouseX)
		{
			rotationX += inputX * sensitivityX;
			rotationX = ClampAngle(rotationX, minimumX, maximumX);
			Quaternion rhs3 = Quaternion.AngleAxis(rotationX, Vector3.up);
			base.transform.localRotation = originalRotation * rhs3;
		}
		else
		{
			rotationY += inputY * sensitivityY;
			rotationY = ClampAngle(rotationY, minimumY, maximumY);
			Quaternion rhs4 = Quaternion.AngleAxis(rotationY, Vector3.left);
			base.transform.localRotation = originalRotation * rhs4;
		}
	}

	private void Start()
	{
		if ((bool)GetComponent<Rigidbody>())
		{
			GetComponent<Rigidbody>().freezeRotation = true;
		}
		originalRotation = base.transform.localRotation;
	}

	public static float ClampAngle(float angle, float min, float max)
	{
		if (angle < -360f)
		{
			angle += 360f;
		}
		if (angle > 360f)
		{
			angle -= 360f;
		}
		return Mathf.Clamp(angle, min, max);
	}

	public void SetInput(Vector2 rightStickInput)
	{
		inputX = rightStickInput.x * 0.1f;
		inputY = rightStickInput.y * 0.1f;
	}
}
